<script>
    $(function () {

        <#list table.fields as field>
        <#if field.propertyName == "createTime" && field.search>
var start = {
            fixed: true,
            elem: '#${serviceNameSimple}CreateTime',
            istime: true,
            isclear: false,
            choose: function (data) {
                end.min = data;
                end.start = data
            }
        };
        var end = {
            fixed: true,
            elem: '#${serviceNameSimple}UpdateTime',
            istime: true,
            isclear: false,
            choose: function (data) {
                start.max = data;
            }
        };
        laydate(start);
        laydate(end);
        </#if>
        </#list>

        $('#${serviceNameSimple}ListDiv #${serviceNameSimple}SearchTable').bootstrapTable({
            url: '${r'${rc.contextPath}'}/${table.controllerPath}/list',
            queryParams: function (params) {
                $.each($("#${serviceNameSimple}ListDiv").find("form").serializeArray(), function (key, value) {
                    params[value.name] = value.value;
                });
                return params;
            },
            columns: [{
                field: '',
                title: '序号',
                align: 'center',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            <#list table.fields as field>
                <#if field.propertyName == "idx">
                <#else>
            }, {
                field: '${(field.propertyName)?replace("Id", "Name")}',
                title: '${field.comment}',
                align: 'center',
                visible: ${field.visible?string}<#if field.propertyName == "status">,
                formatter: function (value) {
                    if (value === "OK") {
                        return "启用";
                    } else {
                        return "<span class=\"label label-purple\">禁用</span>";
                    }
                }<#elseif field.propertyName == "yesNo">,
                formatter: function (value) {
                    if (value === "YES") {
                        return "是";
                    } else {
                        return "<span class=\"label label-purple\">否</span>";
                    }
                }
                <#else>

                </#if>
                </#if>
            </#list>
            }, {
                field: 'idx',
                title: '操作',
                align: 'center',
                formatter: function (value) {
                    return '<a class="btn btn-warning btn-xs" onclick="${serviceNameSimple}Edit(\'' + value + '\')">修改</a>&nbsp;' +
                            '<a class="btn btn-primary btn-xs" onclick="${serviceNameSimple}Detail(\'' + value + '\')">详情</a>';
                }
            }],
            sortName: "create_time",
            sortOrder: "desc"
        });

        $("#${serviceNameSimple}SearchButton").click(function () {
            $('#${serviceNameSimple}SearchTable').bootstrapTable("refresh")
        });

        <#--$("#${serviceNameSimple}ListDiv #${serviceNameSimple}Import").click(function () {-->
        <#--    var brandId = $("#${serviceNameSimple}SearchForm #brandId").val();-->
        <#--    refreshJMenu("${r'${rc.contextPath}'}/${table.controllerPath}/import", "批量导入${table.comment}", {brandId: brandId});-->
        <#--});-->

        $("#${serviceNameSimple}ListDiv #${serviceNameSimple}Add").click(function () {
            openWindows("添加${table.comment}", "${r'${rc.contextPath}'}/${table.controllerPath}/edit", null, function (index, layero) {
                ${serviceNameSimple}SubmitForm(index)
            });
        });

        <#list table.fields as field>
        <#if field.propertyName == "locationId">
        $("#${serviceNameSimple}SearchForm #provinceId").change(function () {
            locationWithDefault("#${serviceNameSimple}SearchForm", true, true);
            if ($(this).val() !== '') {
                locationOptions("#${serviceNameSimple}SearchForm #cityId", $(this).val(), 0, false);
            }
        });
        $("#${serviceNameSimple}SearchForm #cityId").change(function () {
            if ($(this).val() === '') {
                locationWithDefault("#${serviceNameSimple}SearchForm", false, true);
            } else {
                locationOptions("#${serviceNameSimple}SearchForm #locationId", $(this).val(), 0, false);
            }
        });
        locationOptions("#${serviceNameSimple}SearchForm #provinceId", 0, 0, false);
        locationWithDefault("#${serviceNameSimple}SearchForm", true, true);
        </#if>
        </#list>

    });

    function ${serviceNameSimple}Edit(value) {
        openWindows("修改${table.comment}", "${r'${rc.contextPath}'}/${table.controllerPath}/edit", {idx: value}, function (index, layero) {
            ${serviceNameSimple}SubmitForm(index)
        });
    }

    function ${serviceNameSimple}Detail(value) {
        refreshJMenu("${r'${rc.contextPath}'}/${table.controllerPath}/detail", "${table.comment}详情", {idx: value});
    }

    function ${serviceNameSimple}Delete(value, index) {
        $.confirm({
            icon: 'fa fa-warning',
            title: '警告：删除后无法恢复',
            content: '确认删除${table.comment}序号【' + index + '】？',
            confirmButton: '确认',
            confirm: function () {
                commonAjaxJson("${r'${rc.contextPath}'}/${table.controllerPath}/delete", {idx: value}, function (data) {
                    $('#${serviceNameSimple}SearchTable').bootstrapTable("refresh")
                });
            },
            cancel: function () {
            }
        });
    }

</script>
<div class="animated wrapper fadeInRight" style="width:100%;height:100%;" id="${serviceNameSimple}ListDiv">
    <div class="ibox">
        <div class="ibox-content">
            <form class="form-horizontal" id="${serviceNameSimple}SearchForm" method="post" onsubmit="return false">
                <div class="row">
                    <div class="col-lg-3 col-md-3 col-xs-6">
                        <div class="input-group">
                            <span class="input-group-addon">单位</span>
                            <select id="institutionId" name="institutionId" class="form-control">
                                <option value="">全部</option>
                                ${r'[#list institutions as so]'}
                                <option value="${r'${'}so.idx}">${r'${'}so.title}</option>
                                ${r'[/#list]'}
                            </select>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-3 col-xs-6">
                        <button type="button" class="btn btn-primary fa fa-search font14 form-control-static" id="${serviceNameSimple}SearchButton">&nbsp;查询</button>&emsp;
                        <button type="button" class="btn btn-warning fa fa-plus font14 form-control-static" id="${serviceNameSimple}Add">&nbsp;添加</button>&emsp;
<#--                        <button type="button" class="btn btn-warning fa fa-user-plus font14 form-control-static" id="${serviceNameSimple}Import">&nbsp;批量导入</button>-->
                    </div>
                </div>
                <br/>
                <div class="row">
                    <#list table.fields as field>
                    <#if field.search>
                    <#if field.propertyName == "status">
                    <div class="col-lg-2 col-md-3 col-xs-4 margin-b-m">
                        <div class="input-group">
                            <span class="input-group-addon">${field.comment}</span>
                            <select class="form-control" name="status" id="status">
                                <option value="">全部</option>
                                ${r'[#list status as s]'}
                                <option value="${r'${s}'}">${r'${'}s.desc}</option>
                                ${r'[/#list]'}
                            </select>
                        </div>
                    </div>
                    <#elseif field.propertyName == "yesNo">
                    <div class="col-lg-2 col-md-3 col-xs-4 margin-b-m">
                        <div class="input-group">
                            <span class="input-group-addon">${field.comment}</span>
                            <select class="form-control" name="yesNo" id="yesNo">
                                <option value="">全部</option>
                                ${r'[#list yesNo as s]'}
                                <option value="${r'${s}'}">${r'${'}s.desc}</option>
                                ${r'[/#list]'}
                            </select>
                        </div>
                    </div>
                    <#elseif field.propertyName == "locationId">
                    <div class="col-lg-4 col-md-6 col-xs-12 margin-b-m">
                        <div class="input-group">
                            <span class="input-group-addon">${field.comment}</span>
                            <select name="provinceId" id="provinceId" class="form-control width-333"></select>
                            <select name="cityId" id="cityId" class="form-control width-333"></select>
                            <select name="locationId" id="locationId" class="form-control width-333"></select>
                        </div>
                    </div>
                    <#elseif field.propertyName == "createTime">
                    <div class="col-lg-4 col-md-6 col-xs-12 margin-b-m">
                        <div class="input-group">
                            <span class="input-group-addon">创建时间</span>
                            <input type="text" class="form-control laydate-icon" name="createTime" id="${serviceNameSimple}CreateTime" value="${r'${.now?string("yyyy-MM-dd")}'} 00:00:00">
                            <span class="input-group-addon">到</span>
                            <input type="text" class="form-control laydate-icon" name="updateTime" id="${serviceNameSimple}UpdateTime" value="${r'${.now?string("yyyy-MM-dd")}'} 23:59:59">
                        </div>
                    </div>
                    <#else>
                    <div class="col-lg-3 col-md-4 col-xs-6 margin-b-m">
                        <div class="input-group">
                            <span class="input-group-addon">${field.comment}</span>
                            <input type="text" class="form-control" name="${field.propertyName}" id="${field.propertyName}">
                        </div>
                    </div>
                    </#if>
                    </#if>
                    </#list>
                </div>
            </form>
            <table class="table table-bordered" id="${serviceNameSimple}SearchTable"></table>
        </div>
    </div>
</div>
